package com.example.androidcomplete0102.ch19;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;

import com.example.androidcomplete0102.R;

public class LongTime2 extends Activity {
	int mValue;
	TextView tv;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch19_uploadex);
		tv = (TextView) findViewById(R.id.ch19_text);
	}

	Handler mHandler = new Handler() {

		@Override
		public void handleMessage(Message msg) {

			if (msg.what == 0) {
				mValue++;
				tv.setText(Integer.toString(mValue));
				try {
					Thread.sleep(50);
				} catch (InterruptedException e) {
				}
				if (mValue < 100)
					mHandler.sendEmptyMessage(0);
			}
		}
	};

	public void mOnClick(View v) {
		mValue = 0;
		mHandler.sendEmptyMessage(0);
	}

}
